﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AidBrella.BLL;
using AidBrella.ViewModels;

namespace AidBrella.Controllers
{
    [Authorize]
    public class ProfileController : Controller
    {
        private  readonly  UserModel _userModel = new UserModel();

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// Returns MappableViewModel for Projects User is involved
        /// </summary>
        /// <returns></returns>
        public  virtual  ActionResult GetUserProjects()
        {
            var service = new ProjectViewModelService();
            var userId = _userModel.GetUserId(HttpContext.User.Identity.Name);

            var p = service.GetUserProjectsOnMap(userId);

             return Json(new
            {
                points = p.Select(item => new { lat = item.Latitude, lon = item.Longitude, name = item.Name, desc = item.Description, id = item.Id })
            }
                             , JsonRequestBehavior.AllowGet);
        }

        public  ActionResult Account(int id)
        {
           
            var user = _userModel.GetUser(id);
            var uvm = new UserViewModel
                          {
                              FirstName = user.FirstName,
                              LastName = user.LastName,
                              UserName = user.UserName,
                              Email = user.Email
                          };

            return View(uvm);
        }

      

    }
}
